import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh'
// 返回多久之前...
export const timeAgo = (targetTime) => {
  // 格式化时间
  dayjs.extend(relativeTime)
  dayjs.locale('zh')
  const a = dayjs()
  const b = dayjs(targetTime)
  return a.to(b)
}
// 格式化时间
export const formatDate = (targetTime) => {
  return dayjs(targetTime).format('YYYY-MM-DD')
}

// 获得当前时间的前一百年的时间
export const getbefore = (targetTime) => {
  const before = new Date(dayjs(targetTime).subtract(100, 'year'))
  return before
}
